package com.intelligentpension.kotlinsimpleroom.dao

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

/**
 * 版权：点赞 版权所有
 * author :赵航
 * @e-mail: zhaohangcn@gmail.com
 * time：2022/3/26
 * describe ：根据文档,管理basic类
 * entities是关联各种实体类
 * version 版本号
 * 使用exportSchema将数据库模式导出到给定的文件夹。默认为true。
 */
@Database(entities = [User::class], version = 1)//, exportSchema = false)
abstract class RoomBasic : RoomDatabase() {
    companion object {
        private var database: RoomBasic? = null
        private val DATABASE_NAME: String = "db.db"
        fun getDatabase(context: Context): RoomBasic {
            if (database == null) {
                database = Room.databaseBuilder(
                    context.applicationContext,
                    RoomBasic::class.java,
                    DATABASE_NAME
                )
                    .allowMainThreadQueries()
                    .fallbackToDestructiveMigration()
                    .build()
            }
            return database as RoomBasic
        }
    }

    //这句话是核心
    abstract fun UserDao(): UserDao
}